﻿@using System

@page "/Guess A Number"

<PageTitle>Guess A Number</PageTitle>

<h1>Guess&nbsp;A&nbsp;Number</h1>

<a href="https://github.com/dotnet/dotnet-console-games/tree/main/Projects/Guess%20A%20Number" alt="Go To Readme">
	<img title="Go To Readme" alt="Go To Readme" src="https://raw.githubusercontent.com/dotnet/dotnet-console-games/main/.github/resources/readme-black.svg">
</a>

<div class="console-window text-center my-3" @onkeydown="@Console.OnKeyDown" tabindex="0">
	<div class="d-inline-block bg-dark text-light border p-2 text-start shadow padding-0">
		<pre class="console">
			<code>@Console.State</code>
		</pre>
	</div>
	<div>
		@for (char i = '0'; i <= '9'; i++)
		{
			char c = i;
			<span></span>
			<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.D0 + c - '0')">@c</button>
			<span></span>
		}
		<button class="btn btn-primary" @onclick="() => Console.EnqueueInput(ConsoleKey.Enter)">enter</button>
	</div>
</div>

<div class="alert alert-secondary" role="alert">
	&#9000; Keyboard input is supported if you <strong>click</strong> on the game.
</div>

<div class="alert alert-secondary" role="alert">
	&#8635; You can restart the game by <strong>refreshing</strong> the page.
</div>

@code
{
	Games.Guess_A_Number.Guess_A_Number Game;
	BlazorConsole Console;

	public Guess_A_Number()
	{
		Game = new();
		Console = Game.Console;
		//Console.WindowWidth = PLACEHOLDER;
		//Console.WindowHeight = PLACEHOLDER;
		Console.TriggerRefresh = StateHasChanged;
	}

	protected override void OnInitialized() => InvokeAsync(Game.Run);
}
